import java.util.*;

public class HexToDecimalConversion {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Ievadi hexu: ");
        String hex = scan.nextLine();
        
        System.out.println("Decimālā vērtība no dotās hex vērtības "
                + hex + " is " + hexToDecimal(hex.toUpperCase()));
    }
    
    public static int hexToDecimal(String hex) {
        int decimalValue = 0;
        for (int i = 0; i < hex.length(); i++) {
            char hexChar = hex.charAt(i);
            decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar);
        }
        
        return decimalValue;
    }
    
    public static int hexCharToDecimal(char ch) {
        if (ch >= 'A' && ch <= 'F') {
            return 10 + ch - 'A';
        }
        else
            return ch - '0';
    }
}